//package com.analysis.controller;
//
//import com.analysis.utils.RedisChatMemory;
//import com.analysis.dto.ApiResponse;
//import com.fasterxml.jackson.core.type.TypeReference;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import org.springframework.ai.chat.client.ChatClient;
//import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.List;
//
//import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY;
//import static org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor.CHAT_MEMORY_RETRIEVE_SIZE_KEY;
//
//@RestController
//public class ChatRedisMemoryController {
//
//    private final ChatClient chatClient;
//
//    public ChatRedisMemoryController(ChatClient.Builder builder) {
//        this.chatClient = builder
//                .defaultAdvisors(new MessageChatMemoryAdvisor(new RedisChatMemory(
//                        "127.0.0.1",
//                        6379,
//                        null)))
//                .defaultSystem("结果按照顺序输出，返回列表").build();
//    }
//
//
//    @GetMapping(value = "/redis/chat", produces = "text/html;charset=utf-8")
//    public ResponseEntity<ApiResponse<String>> chat(String input, String id) {
//        try {
//            String response = this.chatClient.prompt()
//                    .user(input).advisors(
//                            a -> a
//                                    .param(CHAT_MEMORY_CONVERSATION_ID_KEY, id)  // 记忆用户Id
//                                    .param(CHAT_MEMORY_RETRIEVE_SIZE_KEY, 100) // 总共记录100次
//                    )
//                    .call()
//                    .content();
//            return ResponseEntity.ok(ApiResponse.success(response));
//        } catch (Exception e) {
//            return ResponseEntity.ok(ApiResponse.error("聊天失败: " + e.getMessage()));
//        }
//    }
//
//
//    @GetMapping("/redis/movies")
//    public ResponseEntity<ApiResponse<ActorFilms>> movies(@RequestParam(value = "input") String input) {
//        try {
//            String json = this.chatClient.prompt()
//                    .user(input)
//                    .call()
//                    .content();
//            ActorFilms result = new ObjectMapper().readValue(json, ActorFilms.class);
//            return ResponseEntity.ok(ApiResponse.success(result));
//        } catch (Exception e) {
//            return ResponseEntity.ok(ApiResponse.error("获取电影信息失败: " + e.getMessage()));
//        }
//    }
//
//    @GetMapping("/redis/movies2")
//    public ResponseEntity<ApiResponse<List<ActorFilms>>> movies2(@RequestParam(value = "input") String input) {
//        try {
//            String json = this.chatClient.prompt()
//                    .user(input)
//                    .call()
//                    .content();
//            List<ActorFilms> result = new ObjectMapper().readValue(json, new TypeReference<List<ActorFilms>>() {
//            });
//            return ResponseEntity.ok(ApiResponse.success(result));
//        } catch (Exception e) {
//            return ResponseEntity.ok(ApiResponse.error("获取电影列表失败: " + e.getMessage()));
//        }
//    }
//
//
//    /**
//     * 演员电影信息类
//     */
//    static class ActorFilms {
//        private final String actor;
//        private final List<String> movies;
//
//        public ActorFilms(String actor, List<String> movies) {
//            this.actor = actor;
//            this.movies = movies;
//        }
//
//        public String getActor() {
//            return actor;
//        }
//
//        public List<String> getMovies() {
//            return movies;
//        }
//    }
//
//}